package com.robusta.spreadsheet.describe;

import com.robusta.spreadsheet.describe.jaxb.Context;

import javax.xml.bind.JAXBException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public abstract class WorkbookInfoFactory {
    static Context context;

    public static WorkbookInfo buildFrom(InputStream inputStream) throws JAXBException {
        return initAndGetContext().unmarshal(inputStream);        
    }
    
    public static WorkbookInfo buildFrom(File file) throws FileNotFoundException, JAXBException {
        return buildFrom(new FileInputStream(file));
    }

    private static Context initAndGetContext() throws JAXBException {
        if(context == null) {
            context = new Context();
        }
        return context;
    }
}
